//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    motto: '测试手机里的秘密',
    phone:'',
    result:'',
    img:"",
    rules:[
      [
        "失眠的夜里", "光棍节", "失恋了", "无聊的周末", "大病初愈", "雷电交加的夜晚", "喝醉了酒", "情人节晚上", "等爱人出差了","吃饱以后"
      ],
      [
        "在浴池", "在下水道里", "在小溪边", "在马背上", "在地毯上", "在酒吧", "在高中教室", "在电影院", "在公交车上","在厕所"
      ],
      [
        "跟梦中情人", "跟心中偶像", "跟隔壁吴老二", "跟猥琐怪蜀黍", "跟大胖子", "跟保洁阿姨", "跟老奶奶", "跟数学老师", "跟初恋情人","跟无家可归的小女孩"
      ],
      [
        "唱《爱上一个不回家的人》", "比赛吃蟑螂", "紧紧的拥抱在一起", "背靠背坐在一起", "静静的看着彼此", "接吻", "憧憬你们美好的未来", "一起光着身子跑来跑去", "玩真心话大冒险","拉粑粑"
      ]
    ]
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  startTest:function(){
    var phone = this.data.phone;
    var rules=this.data.rules;
    var phones = phone.substr(phone.length - 4, 4).split("");
    this.setData({
      result: "我"+rules[0][parseInt(phones[0])] + rules[1][parseInt(phones[1])] + rules[2][parseInt(phones[2])] + rules[3][parseInt(phones[3])],
      img: "/imgs/" + phones[3]+".gif"
    })
    
  },
  reset: function () {
    this.setData({
      result: '',
      phone:'',
    })

  },
  phoneInput:function(e){//设置手机号
    this.setData({
      phone: e.detail.value
    })
  },
  onShareAppMessage:function(){
    var title = this.data.result ? this.data.result+",快来看一下你手机的秘密":"一起测试你隐藏在你手机里的秘密"
    return {
      title: title,
    }
  },
  saveImg:function(){
    wx.saveImageToPhotosAlbum({
      success(res) {
      }
    })
  }
})
